﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WordNet.Core;
using WordNet.Core.DataContract;
using WordNet.Core.ElementContracts;

namespace WordNet.CoreTests.Parsers
{
    [TestClass]
    public class UnitTestDataLineVerb:UnitTestBase
    {
        const string DATA_LINE_VERB = @"01983615 38 v 09 chase 0 chase_after 0 trail 0 tail 0 tag 0 give_chase 0 dog 0 go_after 1 track 0 017 @ 01982625 v 0000 + 05754113 n 0902 + 10559724 n 0901 + 00316685 n 0902 + 00482745 n 0501 ^ 02008778 v 0501 + 10528871 n 0401 + 00316887 n 0402 + 00316685 n 0301 + 10337901 n 0102 + 07777156 n 0101 + 00316340 n 0102 ^ 01984477 v 0101 ~ 01134363 v 0000 ~ 01984348 v 0000 ~ 01985358 v 0000 ~ 01985988 v 0000 03 + 08 00 + 09 00 + 10 00 | go after with the intent to catch; ""The policeman chased the mugger down the alley""; ""the dog chased the rabbit""";
       
        [ClassInitialize]
        public static void ClassInit(TestContext context)
        {
            Container = MEFLoader.Load();
        }

        [TestMethod]
        public void CanParseVerbData()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);

        }

        [TestMethod]
        public void CanParseVerbDataOffset()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);
            Assert.AreEqual(int.Parse("01983615"), synset.Offset);

        }

        [TestMethod]
        public void CanParseVerbDataLexFile()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);
            Assert.AreEqual(38, synset.LexicalFile.Number);
            Assert.AreEqual(POS.VERB, synset.LexicalFile.PartOfSpeech);
            Assert.AreEqual(LexFile.VERB_MOTION.Name, synset.LexicalFile.Name);

            Assert.AreEqual(LexFile.GetLexicalFile(38), synset.LexicalFile);

        }

        [TestMethod]
        public void CanParseVerbDataPOS()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);
            Assert.AreEqual(POS.VERB, synset.PartOfSpeech);

        }

        [TestMethod]
        public void CanParseVerbDataNumberOfWords()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);

            Assert.AreEqual(Convert.ToInt32("09", 16), synset.GetWords().Count);
        }

        [TestMethod]
        public void CanParseVerbDataWords()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);

            string expectedValue = "chase";
            Assert.AreEqual(expectedValue, synset.GetWord(1).Lemma);
            Assert.AreEqual(0, synset.GetWord(1).LexicalID);

            expectedValue = "chase_after";
            Assert.AreEqual(expectedValue, synset.GetWord(2).Lemma);
            Assert.AreEqual(0, synset.GetWord(2).LexicalID);

            expectedValue = "trail";
            Assert.AreEqual(expectedValue, synset.GetWord(3).Lemma);
            Assert.AreEqual(0, synset.GetWord(3).LexicalID);

            expectedValue = "tail";
            Assert.AreEqual(expectedValue, synset.GetWord(4).Lemma);
            Assert.AreEqual(0, synset.GetWord(4).LexicalID);

            expectedValue = "tag";
            Assert.AreEqual(expectedValue, synset.GetWord(5).Lemma);
            Assert.AreEqual(0, synset.GetWord(5).LexicalID);

            expectedValue = "give_chase";
            Assert.AreEqual(expectedValue, synset.GetWord(6).Lemma);
            Assert.AreEqual(0, synset.GetWord(6).LexicalID);

            expectedValue = "dog";
            Assert.AreEqual(expectedValue, synset.GetWord(7).Lemma);
            Assert.AreEqual(0, synset.GetWord(7).LexicalID);

            expectedValue = "go_after";
            Assert.AreEqual(expectedValue, synset.GetWord(8).Lemma);
            Assert.AreEqual(1, synset.GetWord(8).LexicalID);

            expectedValue = "track";
            Assert.AreEqual(expectedValue, synset.GetWord(9).Lemma);
            Assert.AreEqual(0, synset.GetWord(9).LexicalID);
        }

        [TestMethod]
        public void CanParseVerbDataSemanticPointers()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);

            Assert.AreEqual(5, synset.GetRelatedSynsets().Count);
            Assert.AreEqual(2, synset.GetRelatedMap().Count);
            Assert.IsTrue(synset.GetRelatedMap().ContainsKey(Pointer.HYPERNYM));
            Assert.IsTrue(synset.GetRelatedMap().ContainsKey(Pointer.HYPONYM));
        }

        [TestMethod]
        public void CanParseVerbDataLexicalPointers()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);
            Assert.IsTrue(synset.GetWord(5).GetRelatedMap().Count == 2);
            Assert.IsTrue(synset.GetWord(5).GetRelatedMap().ContainsKey(Pointer.DERIVATIONALLY_RELATED));
            Assert.IsTrue(synset.GetWord(5).GetRelatedMap().ContainsKey(Pointer.ALSO_SEE));
            Assert.AreEqual(int.Parse("00482745"), synset.GetWord(5).GetRelatedWords()[0].SynsetID.Offset);
            Assert.AreEqual(1, synset.GetWord(5).GetRelatedWords()[0].WordNumber);

            Assert.AreEqual(int.Parse("02008778"), synset.GetWord(5).GetRelatedWords()[1].SynsetID.Offset);
            Assert.AreEqual(1, synset.GetWord(5).GetRelatedWords()[0].WordNumber);
        }

        [TestMethod]
        public void CanParseVerbDataFrames()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);
            //f_cnt    +    f_num  w_num  
            Assert.IsTrue(synset.GetWord(1).GetVerbFrames().Count == 3);
            Assert.AreEqual(8, synset.GetWord(1).GetVerbFrames()[0].Number);
            Assert.AreEqual(9, synset.GetWord(1).GetVerbFrames()[1].Number);
            Assert.AreEqual(10, synset.GetWord(1).GetVerbFrames()[2].Number);
        }

        [TestMethod]
        public void CanParseNounDataGloss()
        {
            IParser<ISynset> dataLineParser = Container.GetExportedValue<IParser<ISynset>>();
            ISynset synset = dataLineParser.Parse(DATA_LINE_VERB);
            Assert.IsNotNull(synset);
            Assert.IsTrue(DATA_LINE_VERB.Trim().EndsWith(synset.Gloss));

        }
    }
}
